#include <sw/redis++/redis.h>
#include <iostream>
#include <chrono>

int main()
{

    try
    {
        sw::redis::ConnectionOptions conn_opts = {
            .host = "192.168.194.128",
            .password = "123456"
        };
        sw::redis::ConnectionPoolOptions  pool_opts = {
            .size = 10,
            .connection_idle_time = std::chrono::milliseconds(3600)
        };
        sw::redis::Redis redis(conn_opts, pool_opts);

        //对数组list进行操作
        //1，从左侧插入数据
        redis.lpush("skills", "C++");
        std::vector<std::string> arr = {"Python", "Java", "C"};
        redis.lpush("skills", arr.begin(), arr.end());
        //2,从右侧获取数据(就类似于队列， 如果从左侧开始获取数据类似于栈)
        int len = redis.llen("skills");
        for (int i = len - 1; i >= 0; --i) {
            auto val = redis.lindex("skills", i);
            std::cout << *val << " "; 
        }
        std::cout << std::endl;

        std::vector<std::string> skills;
        redis.lrange("skills", 0, -1, std::back_inserter(skills));
        for (auto &val : skills) {
            std::cout << val << " ";
        }

    }
    catch(const sw::redis::Error& e)
    {
        std::cout << "redis error:" << e.what() << std::endl;
    }


    return 0;
}
